<%@ page language="java" pageEncoding="UTF-8"
	contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<% 
String basePath = request.getContextPath()+"/"; 
%>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--360浏览器优先以webkit内核解析-->
<title>- 主页示例</title>
<style type="text/css">
<!--
去除边框样式 -->.bootstrap-table>.fixed-table-container>.fixed-table-body>.table>tbody>tr>td
	{
	border: 0px;
}
</style>
<link rel="shortcut icon" href="favicon.ico">
<link href="<%=basePath%>static/css/bootstrap.min.css" rel="stylesheet">
<link href="<%=basePath%>static/jquery-validation/1.11.1/jquery.validate.min.css" rel="stylesheet" />
<!-- 全局js -->
<script src="<%=basePath%>static/js/jquery.min.js?v=2.1.4"></script>
<script src="<%=basePath%>static/js/bootstrap.min.js?v=3.3.6"></script>
<!-- <script src="<%=basePath%>static/js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="<%=basePath%>static/js/plugins/slimscroll/jquery.slimscroll.min.js"></script> -->
<!-- 自定义js -->
<script src="<%=basePath%>static/js/hAdmin.js?v=4.1.0"></script>
<script type="text/javascript" src="<%=basePath%>static/js/index.js"></script>
<script src="<%=basePath%>static/js/plugins/layer/layer.min.js"></script>
<link href="<%=basePath%>static/css/font-awesome.css?v=4.4.0"
	rel="stylesheet">
<link href="<%=basePath%>static/css/animate.css" rel="stylesheet">
<link href="<%=basePath%>static/css/style.css?v=4.1.0" rel="stylesheet">
<link
	href="<%=basePath%>static/css/plugins/bootstrap-table/bootstrap-table.min.css"
	rel="stylesheet" />
<script
	src="<%=basePath%>static/js/plugins/bootstrap-table/bootstrap-table-all.js"></script>
<script
	src="<%=basePath%>static/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script
	src="<%=basePath%>static/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script
	src="<%=basePath%>static/js/plugins/bootstrap-table/closable-tab.js"></script>
<!-- validate -->
<script src="<%=basePath%>static/jquery-validation/1.11.1/jquery.validate.js"></script>
<script src="<%=basePath%>static/jquery-validation/1.11.1/jquery.validate.method.js"></script>
<!-- jquery form  -->
<script src="<%=basePath%>static/js/form.js"></script>
<script src="<%=basePath%>static/js/jquery.form.js"></script>
<!-- 序列化表单  -->
<script src="<%=basePath%>static/js/formSerializeJson.js"></script>
<link
	href="<%=basePath%>static/css/bootstrap-table-sticky-header.css"
	rel="stylesheet" />
<script src="<%=basePath%>static/js/bootstrap-table-sticky-header.js"></script>
<style type="text/css">
.btn {
	width: 100px;
	height: 28px;
	font-size: 11px;
}

body {
	font-size: 11px;
}
</style>
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight"
		style="padding-bottom: 0px">
		<div class="row">
			<div class="col-sm-12" id="renwu">
					<div class="ibox float-e-margins"> 
						<div class="ibox-content">
							<form id="search-form" role="form" class="form-inline">
								<div class="form-group col-sm-3 col-md-3">
									<label >代码类别:</label>
									<input type="text" name="stdCatType" id="stdCatType" class="form-control" style="height:25px;width:180px">
								</div>
								
								<div class="form-group col-sm-3 col-md-3">
									<label >类别名称:</label>
									<input type="text" name="stdCatName" id="stdCatName" class="form-control" style="height:25px;width:180px">
								</div>
								
								<div class="form-group col-sm-3 col-md-3">
									<button class="btn btn-info" type="button" id="ok">查询</button>
									&nbsp;&nbsp;
									<button class="btn btn-info" id="empty"  type="button">清空</button>
								</div>
							</form>
							<br>
							<br>
							<div class="row row-lg">
								<div class="col-sm-12 col-md-12 col-lg-12">
									<!-- Example Events -->
									<div class="example-wrap">
										<div class="example bootstrap-table" id="list-page">
											<table id="table" style="font-size:11px;"> 
											</table> 
										</div>
									</div>
									<!-- End Example Events -->
								</div>
						    </div>
							
							
							<!-- 工具栏 -->
							<div id="toolbar">
								<button type="button" class="btn btn-info btn-sm"
									id="add">
									<i class="middle-120"></i>添加
								</button>
								<button type="button" class="btn btn-info btn-sm"
									id="update">
									<i class="middle-120"></i>编辑
								</button>
								<button type="button" class="btn btn-info btn-sm"
									id="delete">
									<i class="middle-120"></i>删除
								</button>
								<button type="button" class="btn btn-info btn-sm"
									id="import">
									<i class="middle-120"></i>导入
								</button>
								<form style="display: none;" id="importCategory" method="post" enctype="multipart/form-data">
									   <input type="file" name="file" id="file" value="" accept=".xls,.xlsx" />
								</form>
								<button type="button" class="btn btn-info btn-sm"
									id="export">
									<i class="middle-120"></i>导出
								</button>
								<button type="button" class="btn btn-info btn-sm"
									id="downloadTemplete">
									<i class="middle-120"></i>下载Excel模版
								</button>
							</div>
		</div>
	</div>
	
<script>
	$(function(){
		var $table = $('#table');
		    $table.bootstrapTable({
	    	iconSize:'sm',
	    	url : "<%=basePath%>rest/codemanager/category/list",
			toolbar:'#toolbar',
			cache: false,
			height:200,
			stickyHeader: true,
			singleSelect:false,
			clickToSelect:false,
			striped : true,
			pagination : true, 
			pageNumber : 1,//首页页码
			pageSize : 10,//页面显示条数
			pageList : [10, 25, 50, 100 ],
			sidePagination : 'server',//服务器端分页
			showExport: true,
			exportTypes: ['xlsx', 'excel'],  //导出文件类型  
			columns : [
			    {checkbox : true}, 
			 	{field:"stdCatType",title : "代码类别",cellStyle:function(value, row, index, field){return {css: {"border": "0px"}}}},
				{field:"stdCatName",title : "类别名称",cellStyle:function(value, row, index, field){return {css: {"border": "0px"}}}},
				{field:"createTime",title:"创建时间",cellStyle:function(value, row, index, field){return {css: {"border": "0px"}}}},
				{field:"modefyTime",title:"修改时间",cellStyle:function(value, row, index, field){return {css: {"border": "0px"}}}},
				{field:"creatorName",title:"创建人",cellStyle:function(value, row, index, field){return {css: {"border": "0px"}}}},
				{field:"maintainerName",title:"维护人",cellStyle:function(value, row, index, field){return {css: {"border": "0px"}}}},
				],
				contentType : "application/x-www-form-urlencoded",
				queryParamsType : "limit",
				dataType : "json",
				method : "post",
				queryParams : function(params){
					return params;
				}
		});
		
		
		$.each($('table'),function(i, table){
			if($(table).attr('id') != undefined){
				try {
					$(table).bootstrapTable('resetView', {height: $(window).height()-$(".bootstrap-table").offset().top-150});
				} catch (e) {
				}
			}
	    })
		
		//清空事件
		$("#empty").click(function(){
			$("#search-form")[0].reset();
		})
		
		//新增按钮
		$("#add").click(function(){
		    var params = 
			{
				"type": 1,
				"title": "<i class=\"fa fa-desktop\"></i>&nbsp;添加",
				"zIndex": 199206,
				"shade": [0.5,"#000"],
				"closeBtn": 1,
				"maxmin": false,
				"width": "400px",
				"height": "",
				"btn": ["<i class=\"ace-icon fa fa-floppy-o middle-120\"></i>&nbsp;保 存",
				"<i class=\"ace-icon fa fa-times-circle middle-120\"></i>&nbsp;关 闭"],
				"btnAlign": "c",
				"reloadUrl": false,
				"formId": "datamodel-form",
				"success": null,
				"area": ["400px",""],
				"yes" : function(){
					$("#category-addOrUpdate-form").submit();
				 }
            }
		    $.ajax({
		    	url:"<%=basePath%>rest/codemanager/category/toAddOrUpdate",
		    	async:false,
		    	data:{type:"add"},
		    	success:function(data){
		    		params.content = data;
		    	}
		    });
		    layer.open(params);
		})
		
		
		
		//编辑按钮
		$("#update").click(function(){
		   var select = $("#table").bootstrapTable("getSelections");
		   if(select.length<1){
			 layer.open({content:"请选中一条记录编辑"});
			 return false;
		   }else if(select.length>1){
		     layer.open({content:"一次只能编辑一条数据"});
			 return false;
		   }
		   var stdCatId = select[0].stdCatId;
		   var params = 
			{
				"type": 1,
				"title": "<i class=\"fa fa-desktop\"></i>&nbsp;	编辑",
				"zIndex": 199206,
				"shade": [0.5,"#000"],
				"shade": [0.5,"#000"],
				"closeBtn": 1,
				"maxmin": false,
				"width": "400px",
				"height": "",
				"btn": ["<i class=\"ace-icon fa fa-floppy-o middle-120\"></i>&nbsp;保 存",
				"<i class=\"ace-icon fa fa-times-circle middle-120\"></i>&nbsp;关 闭"],
				"btnAlign": "c",
				"fixed": true,
				"moveOut": true,
				"success": null,
				"area": ["400px",""],
				"yes" : function(){
					$("#category-addOrUpdate-form").submit();	
				 }
            }
		    $.ajax({
		    	url:"<%=basePath%>rest/codemanager/category/toAddOrUpdate?stdCatId="+stdCatId,
		    	async:false,
		    	data:{type:"update"},
		    	success:function(data){
		    		params.content = data;
		    	}
		    });
		    layer.open(params);
		})
		
		//删除
		$("#delete").click(function(){
		   var select = $("#table").bootstrapTable("getSelections");
		   var ids = "";
		   if(select.length<1){
			 layer.open({content:"请至少选中一条记录删除"});
			 return false;
		   }
		   else{
			   for(var i=0;i<select.length;i++){
				   ids += select[i].stdCatId+",";
			   }
			   ids = ids.substring(0,ids.length-1);
		   }
		   var data = {"stdCatId":ids};
		   var params = {
				"mode": "del",
				"type": 0,
				"title": "<i class=\"fa fa-desktop\"></i>&nbsp;删除",
				"zIndex": 199206,
				"shade": [0.5,"#000"],
				"closeBtn": 1,
				"width": "50%",
				"height": "",
				"btn": ["<i class=\"ace-icon fa fa-floppy-o middle-120\"></i>&nbsp;确 定",
				"<i class=\"ace-icon fa fa-times-circle middle-120\"></i>&nbsp;取 消"],
				"content": "你确定删除数据吗?",
				"msg": "你确定删除数据吗?",
				"formId": "table-form",
				"fixed": true,
				"moveOut": true,
				"success": null,
				"icon": 3,
				"yes":function(){
					$.post("<%=basePath%>rest/codemanager/category/del",data,function(data){
						if (data.code == 1) {
							layer.open({
								type: 0,
								time: 800,
								icon: 1,
								content: data.msg,
								btn: 0,
								title: false,
								closeBtn: false,
								skin: 'layui-layer-rim',
								end: function(){
			                        layer.closeAll();
			                        //location.reload();
			    					var params = jQuery("#search-form").serializeJson();
			    					$("#table").bootstrapTable("refresh", {query: params});
			                    }
							});
		               } else {
		            	    layer.msg(data.msg,{
		            			time: 2000,
		            			anim:6
		            		});
		               }
					});
				 }
           }
		   layer.open(params);
		})
		
		//导入
	    $("#import").click(function(){
	    	//触发文件框单击事件
	    	$("#file").click();
	    });
		
		//已选择文件  触发导入事件
		$("#file").change(function(){
			var fileName= $("#file").val().substring($("#file").val().lastIndexOf("\\")+1);
			var suffix = fileName.substring(fileName.lastIndexOf(".")+1)
			if(suffix!='xls' && suffix!='xlsx'){
				layer.msg("该文件不是 xls或xlsx文件， 不能进行导入!",{
        			time: 2000,
        			anim:6
        		});
			    return;
			}
			$("#importCategory").ajaxSubmit({
				type:"post",
				url:"<%=basePath%>rest/codemanager/category/importexcel",
				success:function(data){
					if (data.code == 1) {
						layer.open({
							type: 0,
							time: 800,
							icon: 1,
							content: data.msg,
							btn: 0,
							title: false,
							closeBtn: false,
							skin: 'layui-layer-rim',
							end: function(){
		                        layer.closeAll();
		                        location.reload();
		                    }
						});
	               } else {
	            	    layer.msg(data.msg,{
	            			time: 2000,
	            			anim:6
	            		});
	               }
				}
			});
		});
		
		//导出  需求  导出 即全部导出
		$("#export").click(function(){
			//创建临时表单
			var $tempForm = $("<form style='display:none;'></form>");
			$("body").append($tempForm);
			$tempForm.attr("action", "<%=basePath%>rest/codemanager/category/excelexport");
			$tempForm.attr("method", "post");
			$tempForm.submit();
			$tempForm.remove();
		})
		
		//下载模板
		$("#downloadTemplete").click(function(){
			//创建临时表单
			var $tempForm = $("<form style='display:none;'></form>");
			$("body").append($tempForm);
			$tempForm.attr("action", "<%=basePath%>rest/codemanager/category/downloadTemplete");
			$tempForm.attr("method", "post");
			$tempForm.submit();
			$tempForm.remove();
		});
		
		//模糊查询
		$("#ok").click(function(){
			//获得表单内容
			var params = jQuery("#search-form").serializeJson();
			$("#table").bootstrapTable("refresh", {query: params});
		});
	});

</script>